<?
require_once ("util/Transformer.php");
require_once ("util/Generator.php");
require_once ("dao/ChancelaDAO.php");
require_once ("dao/utilsDAO.php");

class MsupRecortarImagem {
	
	public function execute() {
		
		
		$Chancela = new ChancelaDAO();
		$image = $Chancela->getChancela($_REQUEST['idChancela']); //'temp/fingerprints.jpg';

		$image = $image[0];
		
		$dest_image = 'temp/chancela_'.$_REQUEST['idChancela'].'.jpg'; // make sure the directory is writeable

		$margin = 10; // to keep the image and layer in sync
		
		$img = imagecreatetruecolor($_REQUEST['width'], $_REQUEST['height']);
		$org_img = imagecreatefromstring($image); //imagecreatefromjpeg($image);
		//$ims = getimagesize($image);
		$ims[0] = imagesx($org_img);
		$ims[1] = imagesy($org_img);
		imagecopy($img, $org_img, 0, 0, $_REQUEST['tx'], $_REQUEST['ty'], $ims[0], $ims[1]);
		imagejpeg($img, $dest_image, 90);
		imagedestroy($img);
		
		
		$resultado = $Chancela->alteraChancela($_REQUEST['idChancela'],$_REQUEST['nome'],$dest_image,$_REQUEST['validade']);

		unlink($dest_image);
		
            return $resultado;	
	}
	

}

?>